package demo5;

import java.util.*;

@SuppressWarnings({"all"})
public class test {
    public static void main(String[] args) {
        //使用泛型的方式往这个里面放进去三个学生对象
        HashSet<Student> students = new HashSet<Student>();
        students.add(new Student("jack",12));
        students.add(new Student("tom",15));
        students.add(new Student("lucy",18));
        //遍历的方式
        for (Student student : students) {
            System.out.println(student);
        }

        HashMap<String,Student> map = new HashMap<String,Student>();
        map.put("jack1",new Student("tom",25));
        map.put("jack2",new Student("tom",26));
        map.put("jack3",new Student("tom",27));
        Set<Map.Entry<String, Student>> entries = map.entrySet();
        Iterator<Map.Entry<String, Student>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Student> next =  iterator.next();
            System.out.println(next.getKey()+"-"+next.getValue());
        }
    }
}

class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
